package org.qqcui.designpattern.patterns.strategy;

/**
 * 鸭子的抽象类
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/5/7 15:15
 **/
public abstract class Duck {
    FlyBehavior flyBehavior;

    QuackBehavior quackBehavior;

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

    public abstract void display();

    public void swim() {
        System.out.println("鸭子会游泳");
    }

    public void quack() {
        if (quackBehavior != null) {
            quackBehavior.quack();
        }
    }

    public void fly() {
        if (flyBehavior != null) {
            flyBehavior.fly();
        }
    }
}
